
<?php
function V_CatSanphamList($arrayData_parent_id0,$arrayData_parent_id)
{
	$ulr = "?".MODUL."=catSanpham&".ACTION."=";//htmlspecialchars($_SERVER['QUERY_STRING']);
	$ulr1 = "?".MODUL."=sanpham&".ACTION."=";
	global $db;
	include_once(DIR_MODEL."md_san_pham.class.php");
	$objcatSanpham = new MD_Sanpham($db);
	$arrayDataView0 =  array();   
	$arrayDataView = array();
	
	include_once(DIR_MODEL."md_cat_san_pham.class.php");
	$objModel = new MD_CatSanpham($db);
	
	//phan trang
	$totalRows = 0;
	$paging="";
	$totalRows=count($arrayData_parent_id0);
	$maxRows = MAXROW;
	$maxPages =MAXPAGES;
	if($totalRows%$maxRows==0)
		$totalPages = (int)($totalRows/$maxRows);
	else
		$totalPages = (int)($totalRows/$maxRows+1);
	$curPage =CM_getParameter("curPg");
	if($curPage=="")
		$curPage =1;
	else
		$curRow = ($curPage-1)*$maxRows+1;
	$paging ="Trang thứ :&nbsp;<font color=red>".$curPage."</font>&nbsp;&nbsp;&nbsp;"."Tổng số trang :&nbsp;<FONT color=red>".$totalPages."</FONT><br> ";
	if($totalRows>$maxRows)
	{
		$start=1;
		$end=1;
		$paging1 ="";
		for($i=1;$i<=$totalPages;$i++)
		{
			if(($i>((int)(($curPage-1)/$maxPages))* $maxPages) && ($i<=((int)(($curPage-1)/$maxPages+1))* $maxPages))
			{
				if($start==1) $start=$i;
					if($i==$curPage)
						$paging1 .=  $i."&nbsp;&nbsp;";
					else
						$paging1 .= "<a href='javascript:GotoPage(".$i.")'>".$i."</a>&nbsp;&nbsp;";
				$end=$i;
			}
		}
		$paging.= "Chọn trang :&nbsp;&nbsp;" ;
		if($curPage>$maxPages)
			$paging .="<a href='javascript:GotoPage(".($start-1).")'>Trở về</a>&nbsp;&nbsp;";
		$paging.=$paging1;
		if(((($curPage-1)/$maxPages+1)*$maxPages) < $totalPages)
			$paging .= "<a href='javascript:GotoPage(".($end+1).")'>Tiếp</a>&nbsp;&nbsp;";
	}
?>
<?= CM_showError() ?>
<script>
function CheckVewHomepage(){
	var checkedbox = 0;
	for (var i=0;i<document.search1.elements.length;i++)
	{
		var e=document.search1.elements[i];
		if ((e.type=='checkbox')){
			if (e.checked == true)
			{
				checkedbox = checkedbox + 1;
			}
		}
	}
	//Khi khong chon mot checkbox nao
	if (checkedbox == 0){
	
		alert("Bạn hãy chọn ít nhất một loại sản phẩm để hiển thị lên trang chủ.");
		return false;
	}
	//Khi chon so luong checkbox nhieu hon 3 check
	if (checkedbox > 3){
		//alert(checkedbox);
		alert("Bạn chỉ có thể chọn nhiều nhất là 3 loại sản phẩm để hiển thị lên trang chủ.");
		return false;
	}
	return true;
}
//Dem so vi tri da check
function GotoPage(iPage){	
	document.search1.action =document.search1.action  + "&curPg="+iPage;
	document.search1.submit()  ;
}		
</script>
   <font color="#FF0000" size="4">Loại sản phẩm :</font>
   <a href="?modul=catSanpham&action=Add" class="thanh_link1"><strong>Thêm mới</strong></a>
   <hr width="24%" size="1" align="left">

  <!-- <form name="search1" action="<?=$ulr?>ViewHomePage"  method="post" enctype="multipart/form-data" onSubmit="return CheckVewHomepage();" >  -->
 <form name="search1" action="<?=$ulr?>List"  method="post" enctype="multipart/form-data" > 
<TABLE width="97%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
  <TBODY>
	  <TR align="center" bgcolor="#FFE59F">
	  	<TD width="27" height="17" align="center" valign="middle" id=th1><strong><font size="2">STT</font></strong></TD>
		<TD width="24" height="17" align="center" valign="middle" id=th1><strong><font size="2">Sửa</font></strong></TD>
		<TD width="27" height="17" align="center" valign="middle" id=th1><strong><font size="2">Xóa</font></strong></TD>
		<TD width="699" align="left" valign="middle" id=th4><strong><font size="2">Tên loại sản phẩm</font></strong></TD>
		<!-- <TD width="229" align="center" valign="middle"><strong><font size="2">Hiển thị ngoài trang chủ</font></strong></TD> -->
		<TD width="138" align="center" valign="middle" id=th4><strong><font size="2">Thứ tự sắp xếp</font></strong></TD>
		<TD width="104" align="center" valign="middle" id=th4><strong><font size="2">Hiển thị</font></strong></TD>
	</TR>
	
	<?
	//=======================================================================================
	if($arrayData_parent_id0!=Null)
	{
		$stt=0;
		$i= 0;
		$low=$curRow;
		$curRow=1;
		
		foreach($arrayData_parent_id0 as $row0)
		{
			$stt+=1;
			$str_hienthi0 = "";
				if($row0["hien_thi"]==1)
				{
					$str_hienthi0 = 'Có';
				}
				else
				{
					$str_hienthi0 = 'Không';
				}
			
			$arrayDataTemp = $objModel -> getByWhere("*","parent_id = ".$row0['id'],"");			
			if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
			{
				$curRow++;
				if($curRow>$low){
					$i+1;			
		?>
			<TR>
				<TD height="22" align=center valign="middle" class=bk12-140 bgcolor="#FFE59F"><strong>
				<font size="2"><?=$stt?></font>
				</strong></TD>
				<TD height="22" align=center valign="middle" class=bk12-140 bgcolor="#FFE59F"><A  href="<?=$ulr."Edit"?>&id=<? echo $row0['id']; ?>&parent_id=<? echo $row0['parent_id']?>"><IMG   title=Change height=16 alt=Change hspace=2   src="../images/Edit.gif" width=16 border=0></A></TD>
				<TD class=bk12-140 bgcolor="#FFE59F" align="center"><a  onClick="return confirmDelete();"   href="<?=$ulr."Delete"?>&id=<? echo $row0['id']; ?>"><img title=Drop height=16 alt=Drop hspace=2 src="../images/Delete.gif" width=16 border=0></a></TD>
				<TD align="left" valign="middle"  class=bk12-140>
				<?
				if(empty($arrayDataTemp)){
				?>
				<a href="<?=$ulr1."List"?>&id_loai_sp=<? echo  $row0['id']; ?>" class="thanh_link">
				<font size="2"><? echo $row0['ten_loai_sp']; ?></font>
				</a>
				<?
				}else{
				?>
				<font size="2" style="font-weight:bold; "><? echo $row0['ten_loai_sp']; ?></font>
				<?
				}
				?>
				</TD>
				
				<TD  valign="middle"  class=bk12-140> <div align="right"><font size="2"><? echo $row0['thu_tu']; ?></font></div></TD>
				<TD width="104" align="center" valign="middle"  class=bk12-140><a href="<?=$ulr."Edit_ht"?>&id=<? echo  $row0['id']; ?>&hien_thi=<?=$row0['hien_thi']; ?>" class="thanh_link"><font size="2"><?=$str_hienthi0?></font></a></TD>
			</TR>
		<?
			
			
			foreach ($arrayData_parent_id as $row){
			
				
				if($row['parent_id']==$row0['id']){
				$stt+=1;
				$str_hienthi = "";
				if($row["hien_thi"]==1)
				{
					$str_hienthi = 'Có';
				}
				else
				{
					$str_hienthi = 'Không';
				}
			   /* $view_o_trang_chu = $row['view_o_trang_chu'];
				if($view_o_trang_chu==1){
					$checked = "checked";
				}else{
					$checked = "";
				}*/
	?>
	  <TR>
	    <TD height="22" align=center valign="middle" class=bk12-140 bgcolor="#FFE59F"><strong>
        <font size="2"><?=$stt?></font>
        </strong></TD>
		<TD height="22" align=center valign="middle" class=bk12-140 bgcolor="#FFE59F"><A  href="<?=$ulr."Edit"?>&id=<? echo $row['id']; ?>&parent_id=<? echo $row['parent_id']?>"><IMG   title=Change height=16 alt=Change hspace=2   src="../images/Edit.gif" width=16 border=0></A></TD>
		<TD class=bk12-140 bgcolor="#FFE59F" align="center"><a  onClick="return confirmDelete();"   href="<?=$ulr."Delete"?>&id=<? echo $row['id']; ?>"><img title=Drop height=16 alt=Drop hspace=2 src="../images/Delete.gif" width=16 border=0></a></TD>
		<TD align="left" valign="middle"  class=bk12-140>&nbsp;&nbsp;&nbsp;<a href="<?=$ulr1."List"?>&id_loai_sp=<? echo  $row['id']; ?>" class="thanh_link"><font size="2"><? echo $row['ten_loai_sp']; ?></font></a></TD>
		
		<TD  valign="middle"  class=bk12-140> <div align="right"><font size="2"><? echo $row['thu_tu']; ?></font></div></TD>
		<TD align="center" valign="middle"  class=bk12-140><a href="<?=$ulr."Edit_ht"?>&id=<? echo  $row['id']; ?>&hien_thi=<?=$row['hien_thi']; ?>" class="thanh_link"><font size="2"><?=$str_hienthi?></font></a></TD>
    </TR>
	    
<?
			}
		  }//foreach ($arrayData_parent_id)
		  } // end if($curRow>$low)
		 }
		} // end foreach  ($arrayData_parent_id0 as $row0)
	}else
	{
?>
	<tr valign="top">
			<td colspan=6 valign=center align="center"><b><font face="Arial" color="#FF0000">Không có bản ghi nào </font></b></td>
     </tr>
<?
	}
?>

</TBODY></TABLE>
<div>&nbsp;</div>

<table border="0" width="99%">
	<!--DWLayoutTable-->
	
	<tr>
		<td width="363" rowspan="2" align=left>
		  <div align="left"><font face="Arial" color="#0066cc">Tổng số bản ghi <b><font color="#ff0000">
			<? echo($totalRows);?></font></b></font></div>
			 <hr width="40%" size="1" align="left">		  
		</td>
		<td width="565" height="23" align=right valign="top"><?=$paging?></td>
	</tr>
	<tr>
	   <td height="15" align="right" valign="top">
		<A class="thanh_link1" href="<?=$ulr."list" ?>">[<strong>Trở về </strong>]</a>&nbsp;&nbsp;&nbsp; 
	   </td>			 
	</tr>
</table>
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>"> 
<input type=hidden name="cat_idS" value="<?=CM_getParameter("cat_idS")?>">
<input type=hidden name="cat_id" value="<?=CM_getParameter("cat_id")?>"> 
<input type=hidden name="showsS" value="<?=CM_getParameter("showsS")?>"> 
<input type=hidden name="curPg" >
</form>

<?php
}
?>